package com.econ.powercloud.ems.domain;

import com.econ.powercloud.common.base.facade.util.JacksonUtil;
import com.econ.powercloud.ems.constant.SysConstant;
import com.econ.powercloud.ems.dal.entity.EmsFeeConfirmConfig;
import com.econ.powercloud.ems.pojo.EmsFeeConfirmConfigVO;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/4/24 11:06
 * @Modified by : zjf
 */
public class EmsFeeConfirmConfigDO {

    public static List<EmsFeeConfirmConfigVO> entityListToVOList(List<EmsFeeConfirmConfig> confirmConfigs){
        if(CollectionUtils.isEmpty(confirmConfigs)){
            return Collections.emptyList();
        }
        List<EmsFeeConfirmConfigVO> configVOS = JacksonUtil.convertToList(confirmConfigs, EmsFeeConfirmConfigVO.class);
        configVOS.stream().forEach(d->{
            if(d.getSorting() != null){
                String[] locations = d.getSorting().split(SysConstant.CABLE);
                //赋值坐标位置,如果不是二维坐标,则横坐标不需要赋值
                d.setGroup(locations.length >1?Integer.parseInt(locations[1]): SysConstant.ONE_INTEGER);
                d.setCross(Integer.parseInt(locations[0]));
            }
        });
        return configVOS;
    }
}
